package tt.dz.mvc.controller.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import tt.dz.entity.base.JsonCommon;
import tt.dz.entity.base.JsonForList;
import tt.dz.entity.base.OmsDeviceType;
import tt.dz.service.base.DeviceTypeService;
import tt.dz.util.ActionUtils;

/**
 * 
 * @author huanghao
 *
 */
@Controller
@RequestMapping("/deivceTypeApi")
public class DeviceTypeAction extends BaseAction
{
	@Autowired
	private DeviceTypeService deviceTypeServiceImpl;
	@RequestMapping(value="add",method=RequestMethod.POST)
	@ResponseBody
	public JsonCommon<?> add(HttpServletRequest request, HttpServletResponse response)
	{
		return deviceTypeServiceImpl.add(this.getObjFromRequest(request,true,false));
	}
	
	@RequestMapping(value="update/{device_id}",method=RequestMethod.POST)
	@ResponseBody
	public JsonCommon<?> update(@PathVariable String device_id,HttpServletRequest request, HttpServletResponse response)
	{
		OmsDeviceType oom = this.getObjFromRequest(request,false,false);
		oom.setDevice_id(device_id);
		return deviceTypeServiceImpl.update(oom);
	}
	
	@RequestMapping(value="delete/{device_id}",method=RequestMethod.POST)
	@ResponseBody
	public JsonCommon<?> delete(@PathVariable String device_id,HttpServletRequest request, HttpServletResponse response)
	{
		return deviceTypeServiceImpl.delete(device_id);
	}
	@RequestMapping(value="findAllOrPage",method=RequestMethod.GET)
	@ResponseBody
	public JsonForList<?> findAllOrPage(HttpServletRequest request, HttpServletResponse response)
	{
		return deviceTypeServiceImpl.findPageObjs(this.buildQueryParam(request, true),this.getObjFromRequest(request, false,true));
	}
	
	private OmsDeviceType getObjFromRequest(HttpServletRequest request,boolean isCreate,boolean isFind)
	{
		String loginUserId = this.getLoginUserId(request);
		return ActionUtils.getParamInstance(OmsDeviceType.class, ActionUtils.getParameterMap(request),loginUserId,isCreate,isFind);
	}
	
}
